package com.sihan.framework.etm.controller;

import com.framework.annotation.BusinessLog;
import com.framework.annotation.ParamParser;
import com.framework.model.ApiResult;
import com.sihan.framework.etm.dto.SecurityParamUpdateDTO;
import com.sihan.framework.etm.entity.SecurityParam;
import com.sihan.framework.etm.service.SecurityParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author QinC
 * @create 2018-09-06 14:44
 */
@Api(tags = "安全参数")
@RestController
@RequestMapping("/system/v0/security")
public class AdminSecurityParamController {

    @Autowired
    private SecurityParamService securityParamService;

    @ApiOperation("查看安全参数")
    @GetMapping("/view")
    @BusinessLog("查看安全参数")
    @RequiresPermissions("sys:manager:security:view")
    public ApiResult<?> getSecurityParam() {
        return ApiResult.success(securityParamService.getSecurity());
    }


    @ApiOperation("修改安全参数")
    @PostMapping("/update")
    @BusinessLog("修改安全参数")
    @RequiresPermissions("sys:manager:security:update")
    public ApiResult<?> updateSecurityParam(@Valid @ParamParser SecurityParamUpdateDTO dto) {
        SecurityParam sp = new SecurityParam();
        BeanUtils.copyProperties(dto, sp);
        securityParamService.updateSecurity(sp);
        return ApiResult.success();
    }
}
